Network Address Translation.html
* created: 2026-05-11T00:00
* modified: 2026-05-11T00:20
title
Title
description
Description
Network Address Translation (NAT)
Mapping private IP addresses to public IP addresses. Each local IP address gets its own port on the public IP, allowing many devices to share a single public address.
How it works
A home router sits between your LAN and the internet. When a device sends a packet out:
- The router replaces the private source IP (192.168.1.x) with its public IP
- It records the mapping in a NAT table: (private IP, private port) <-> public port
- When a reply arrives, the router looks up the table and forwards the packet back to the correct internal device
NAT Traversal
When two peers are both behind NAT, direct connection is non-trivial. Common techniques:
- STUN: Discover your public IP/port
- TURN: Relay traffic through a server when direct fails
- ICE: Tries STUN first, falls back to TURN (used in WebRTC)
- UDP hole punching : Both sides send packets simultaneously to open a path through each other's NAT